package com.zbs.framework.swagger.view;

import com.zbs.framework.swagger.entity.TablesVo;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Zbs
 * @since 2022-01-05
 */
@Getter
@Setter
@Accessors(chain = true)
public class TablesView {

    /**
     * id
     */
    private Integer id;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 表类型[system view|base table]
     */
    private String tableType;

    /**
     * 数据库引擎[MyISAM|CSV|InnoDB]
     */
    private String engine;

    /**
     * 行格式[Compact|Dynamic|Fixed]
     */
    private String rowFormat;

    /**
     * 表的创建时间
     */
    private LocalDateTime createTime;

    /**
     * 字符集编码
     */
    private String encode;

    /**
     * 排序规则
     */
    private String collation;

    /**
     * 表的注释、备注
     */
    private String tableComment;

    /**
     * 表结构
     */
    private List<ColumnsView> columnsViewList;

    public TablesView(Integer id,TablesVo tablesVo,List<ColumnsView> columnsViewList) {
        this.id = id;
        this.tableName = tablesVo.getTableName();
        this.tableType = tablesVo.getTableType();
        this.engine = tablesVo.getEngine();
        this.rowFormat = tablesVo.getRowFormat();
        this.createTime = tablesVo.getCreateTime();
        this.tableComment = tablesVo.getTableComment();
        this.collation = tablesVo.getTableCollation();
        if (StringUtils.hasLength(tablesVo.getTableCollation())) {
            this.encode = tablesVo.getTableCollation().substring(0, tablesVo.getTableCollation().indexOf("_"));
        }
        this.columnsViewList = columnsViewList;
    }


}
